package com.cupk.carManageMaster.api.controller;

import com.cupk.carManageMaster.common.domain.ResponseBase;
import com.cupk.carManageMaster.common.dto.UserDto;
import com.cupk.carManageMaster.core.serviceImpl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@CrossOrigin
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    /**
     * 登陆成功返回token给前台，之后每调一个接口都需要校验token之后有效
     *
     * @return
     */
    @GetMapping("/login")
    @ResponseBody
    @CrossOrigin
    public ResponseBase userLogin(UserDto userDto) {
        return userService.userLogin(userDto.getUsername(), userDto.getPassword());
    }

    /**
     * 查看用户的基本信息
     */
    @GetMapping("/getUserInfo")
    @ResponseBody
    @CrossOrigin
    public ResponseBase getUserInfo(Integer id) {
        return userService.getUserInfo(id);
    }

}
